package 第二十章项目.clothesSystem.ui;

import 第二十章项目.clothesSystem.utils.BusinessException;

import java.text.MessageFormat;

public class Welcome extends BaseClass{


    public void start(){
        println(getString("info.welcome"));
        boolean flag=true;
        while(flag){
            println(getString("info.login.reg"));
            println(getString("info.select"));
            String select=input.nextLine();
            switch(select){
                case "1":
                    try{
                        new LoginClass().login();
                        flag=false;
                        println(getString("login.success"));
                        try {
                            for(int i=2;i>0;i--) {
                                final String format = MessageFormat.format(getString("welcome.login.countdown"), i);
                                System.out.print("\r"+format);
                                Thread.sleep(1000);
                            }
                            System.out.println();
                            println(getString("welcome.login"));
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        HomeClass hc=new HomeClass();
                        hc.show();
                    }catch (BusinessException e) {
                       println(getString("login.error"));
                    }
                    break;
                case "2":
                    //flag=false;
                    try {
                        System.out.println("注册");
                        new RegisterClass().register();
                    }catch (BusinessException e){
                        println(getString("reg.error"));
                    }
                    break;
                case "3":
                    //flag=false;
                    try {
                        System.out.println("查询数据库");
                    }catch (BusinessException e){
                        println(getString("userData.missing.error"));
                    }
                    new UserIO().readUsers();
                    break;
                default:
                    System.out.println("输入错误，请重新输入!");
                    break;
            }
        }

    }

}
